clear

% 
adaptation_costs_raw_data = importdata('/Adaptation Costs Inputs/adaptation_costs_raw_data_futureincome_SSP5.mat');

polyabove_30_2020_vec = adaptation_costs_raw_data(:,1);
polyabove_30_2090_vec = adaptation_costs_raw_data(:,2);
polybelow_5_2020_vec = adaptation_costs_raw_data(:,3);
polybelow_5_2090_vec = adaptation_costs_raw_data(:,4);
beta_hat_hot_2020_vec = adaptation_costs_raw_data(:,5);
beta_hat_hot_2090_vec = adaptation_costs_raw_data(:,6);
beta_hat_hot_serv_2020_vec = adaptation_costs_raw_data(:,7);
beta_hat_hot_serv_2090_vec = adaptation_costs_raw_data(:,8);
beta_hat_cold_2020_vec = adaptation_costs_raw_data(:,9);
beta_hat_cold_2090_vec = adaptation_costs_raw_data(:,10);
beta_hat_cold_serv_2020_vec = adaptation_costs_raw_data(:,11);
beta_hat_cold_serv_2090_vec = adaptation_costs_raw_data(:,12);

% Apply calculations described in Appendix D, using the function
% calc_adaptation costs

total_benefit_hot_vec = polyabove_30_2090_vec.*(beta_hat_hot_2090_vec-beta_hat_hot_2020_vec);
total_costs_hot_vec = calc_adaptation_costs(polyabove_30_2090_vec,polyabove_30_2020_vec,beta_hat_hot_2090_vec,beta_hat_hot_2020_vec,70);

total_benefit_hot_serv_vec = polyabove_30_2090_vec.*(beta_hat_hot_serv_2090_vec-beta_hat_hot_serv_2020_vec);
total_costs_hot_serv_vec = calc_adaptation_costs(polyabove_30_2090_vec,polyabove_30_2020_vec,beta_hat_hot_serv_2090_vec,beta_hat_hot_serv_2020_vec,70);

total_benefit_cold_vec = polybelow_5_2090_vec.*(beta_hat_cold_2090_vec-beta_hat_cold_2020_vec);
total_costs_cold_vec = calc_adaptation_costs(polybelow_5_2090_vec,polybelow_5_2020_vec,beta_hat_cold_2090_vec,beta_hat_cold_2020_vec,70);

total_benefit_cold_serv_vec = polybelow_5_2090_vec.*(beta_hat_cold_serv_2090_vec-beta_hat_cold_serv_2020_vec);
total_costs_cold_serv_vec = calc_adaptation_costs(polybelow_5_2090_vec,polybelow_5_2020_vec,beta_hat_cold_serv_2090_vec,beta_hat_cold_serv_2020_vec,70);

total_benefits_manu = total_benefit_hot_vec+total_benefit_cold_vec;
total_benefits_serv = total_benefit_hot_serv_vec+total_benefit_cold_serv_vec;
total_costs_manu = total_costs_hot_vec+total_costs_cold_vec;
total_costs_serv = total_costs_hot_serv_vec+total_costs_cold_serv_vec;

net_benefits_manu = total_benefits_manu-total_costs_manu;
net_benefits_serv = total_benefits_serv-total_costs_serv;

outputs = [total_costs_manu total_benefits_manu net_benefits_manu total_costs_serv total_benefits_serv net_benefits_serv];

dlmwrite('adaptation_costs_benefits_futureincome_SSP5.csv',outputs)


